package com.ohos.connect.devicecloud.app.modular.project.api;

import com.ohos.connect.devicecloud.app.api.ProjectApi;
import com.ohos.connect.devicecloud.app.model.vo.AppProjectVO;
import com.ohos.connect.devicecloud.app.modular.project.model.vo.ProjectVO;
import com.ohos.connect.devicecloud.app.modular.project.service.ProjectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("projectApi")
public class ProjectApiImpl implements ProjectApi {

    @Resource
    private ProjectService projectService;

    @Override
    public List<AppProjectVO> getAppProjects() {
        List<ProjectVO> projectListByAppUser = projectService.getProjectListByAppUser();

        List<AppProjectVO> result = new ArrayList<>();
        for (ProjectVO projectVO : projectListByAppUser) {
            AppProjectVO appProjectVO = new AppProjectVO();
            appProjectVO.setId(projectVO.getId());
            appProjectVO.setName(projectVO.getName());
            result.add(appProjectVO);
        }

        return result;
    }
}
